﻿using System;
using System.Collections.Generic;
using System.Diagnostics;

namespace Teal.Compiler {

    /// <summary>
    /// 表示一个用于语句的语义分析的上下文。
    /// </summary>
    public sealed partial class ResolveContext {

        /// <summary>
        /// 获取当前正在被解析的成员定义。
        /// </summary>
        public MemberDefinition currentMemberDefinition;

        /// <summary>
        /// 返回当前正在被解析的顶级块。
        /// </summary>
        public ToplevelBlock currentToplevelBlock {
            get {
                for (var c = currentFlowControl; c != null; c = c.parentControl) {
                    var ct = c as ToplevelFlowControl;
                    if (ct != null) {
                        return ct.srcToplevelBlock;
                    }
                }
                return null;
            }
        }

        ///// <summary>
        ///// 获取当前类型。
        ///// </summary>
        //public TypeReference currentType {
        //    get {
        //        return currentMemberDefinition.memberReference.parentType;
        //    }
        //}

        /// <summary>
        /// 当前上下文内的变量计数器。
        /// </summary>
        public int variableCount;

        /// <summary>
        /// 在当前上下文添加变量。
        /// </summary>
        /// <param name="context"></param>
        /// <param name="variables"></param>
        public void addVariables(Variable variables) {
            for (var variable = variables; variable != null; variable = variable.next) {
                variable.index = ++variableCount;
                currentFlowControl.addVariable(variable);
            }
        }

    }

}